/*
 * @Author: airhang
 * @Date: 2020-06-12 11:04:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Socket\app.js
 */
const ws = require("ws");
const webStService = ws.Server;
const colorLog = require("@michaelray/console-color");

const wbs = new webStService({ port: 3030 }, (res) =>
  colorLog.debug("socket启动", "127.0.0.1:3030".yellow)
);

wbs.on("connection", function (ws) {
  console.info("连接成功");

  ws.on("message", function (message) {
    colorLog.info("----------------------------");
    colorLog.debug("接收前端信息", message);
    switch (message) {
      case "HIHI":
        {
          ws.send("HEllo,airhang");
        }
        break;
    }
  });
  ws.send("前端你好");
});
